package com.dyz.wsw.passport.controller;

import com.dyz.wsw.common.pojo.auth.Principal;
import com.dyz.wsw.common.web.JsonResult;
import com.dyz.wsw.passport.pojo.param.UserLoginInfoParam;
import com.dyz.wsw.passport.service.IUserService;
import com.dyz.wsw.security.annotation.Authentication;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;


/**
 * @author dyz
 * @date 2025/2/7 17:27
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Validated
public class UserController {

    private final IUserService userService;

    public UserController(IUserService userService) {
        log.info("创建控制器对象: UserController");
        this.userService = userService;
    }

    @PostMapping("/login")
    public Mono<JsonResult> login(@Valid @RequestBody UserLoginInfoParam loginInfoParam, ServerWebExchange exchange){
        log.debug("开始处理【用户登录】的请求，参数: {}",loginInfoParam);
        return userService.doLogin(loginInfoParam, exchange);
    }


    /**
     * 登出请求
     * @param principal 当事人
     * @return 登录结果
     */
    @PostMapping("/logout")
    public Mono<JsonResult> logout(@Authentication Principal principal){
        return userService.doLogout(principal);
    }


}
